

import { MixIndicator } from "./MixIndicator";

export interface Message {
  type: string;
  [x: string]: any
}

let mixIndicator: MixIndicator;

process.on("message", (msg: Message) => {
  switch (msg.type) {
    case 'init':
      mixIndicator = new MixIndicator({isMock: true});
      mixIndicator.onMixIndicator(( bar, feature_vector_detail) => {
        // 将结果发送给主线程
        process.send({type: 'onMixIndicator', bar, feature_vector_detail});
      });
      break;
    case 'push':
      mixIndicator.push(msg.data, msg.period);
      break;
    case 'update':
      mixIndicator.update(msg.data, msg.period);
  }
});

process.on('SIGTERM', (s) => {
  console.log('接收到 SIGTERM 信号，开始关闭进程...', s);
  // 在这里进行资源清理、保存数据等操作
  process.exit(0);
});